package com.zmy.xcx.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zmy.xcx.project.common.convention.exception.ClientException;
import com.zmy.xcx.project.common.enums.UserErrorCodeEnum;
import com.zmy.xcx.project.dao.entity.MildSymptom;
import com.zmy.xcx.project.dao.entity.TreatmentMethod;
import com.zmy.xcx.project.dao.mapper.TreatmentMethodMapper;
import com.zmy.xcx.project.service.TreatmentMethodService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 治疗方法接口实现层
 */
@Slf4j
@Service
public class TreatmentMethodImpl extends ServiceImpl<TreatmentMethodMapper, TreatmentMethod> implements TreatmentMethodService {
    
    @Override
    public TreatmentMethod getTreatmentMethod(String id) {
        log.info("开始查询治疗方法，id: {}", id);
        try {
            LambdaQueryWrapper<TreatmentMethod> queryWrapper = Wrappers.lambdaQuery(TreatmentMethod.class)
                    .eq(TreatmentMethod::getId, id);
            
            TreatmentMethod treatmentMethod = baseMapper.selectOne(queryWrapper);
            
            if (treatmentMethod == null) {
                log.warn("未找到对应的治疗方法，id: {}", id);
                throw new ClientException(UserErrorCodeEnum.USER_NULL);
            }
            
            log.info("查询治疗方法成功，id: {}", id);
            return treatmentMethod;
        } catch (ClientException e) {
            throw e;
        } catch (Exception e) {
            log.error("查询治疗方法失败，id: {}", id, e);
            throw new ClientException("查询治疗方法失败");
        }
    }
}
